package com.scy.java.object;

//测试学生类
public class StudentDemo {
    public static void main(String[] args) {
//        Student stu1 = new Student();
//        stu1.number= 1;
//        //1-7年纪
//        stu1.state = (int)(Math.random()*6+1);
//        stu1.score = (int)(Math.random()*101);
//        stu1.info();
        //使用对象数组解决
        //创建数组
        Student[] stu = new Student[20];
//        System.out.println(Arrays.toString(stu));
        //循环给数组赋值
        for (int i = 0; i < stu.length; i++) {
            //数组元素赋值
            stu[i] = new Student();
            //数组元素是一个对象，给对象 的各个属性赋值
            stu[i].number = i+1;
            stu[i].state = (int)(Math.random()*6+1);
            stu[i].score = (int)(Math.random()*101);
            stu[i].info();
        }
        System.out.println("---------------------");
//        System.out.println(Arrays.toString(stu));
        //问题一：打印出三年级学生的信息
        for (int i = 0; i < stu.length; i++) {
            if (stu[i].state == 3){
                stu[i].info();
            }
        }
        //冒泡排序，对成绩排序
        System.out.println("---------------------");

        for (int i = 0; i < stu.length-1; i++) {
            for (int j = 0; j < stu.length-i-1; j++) {
                if (stu[j].score > stu[j+1].score){
                    Student s  = stu[j];
                    stu[j]= stu[j+1];
                    stu[j+1]= s;

                }
            }
        }
        //遍历数组
        for (Student s:stu) {
            s.info();
        }


    }

}
